//
//  ModifierPasswordController.m
//  shopping
//
//  Created by 徐双 on 2017/8/31.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "ModifierPasswordController.h"

@interface ModifierPasswordController ()

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UITextField * textField1;
@property (nonatomic, strong) UITextField * textField2;

@end

@implementation ModifierPasswordController

- (void)viewWillAppear:(BOOL)animated{
    
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"设置支付密码"];
    
    [self setUpInputPassword];
    [self setUpInputPasswodAgain];
    [self setUpCongigBtn];
    
}

-(void)setUpInputPassword{

    //设置分割线
    UIView *viewOfLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 1)];
    [self.view addSubview:viewOfLine];
    viewOfLine.backgroundColor = [UIColor colorWithRed:233/255.0f green:233/255.0f blue:233/255.0f alpha:1.0];
    //设置label
    UILabel * label1 = [[UILabel alloc] init];
    
    label1.text = @"请输入新密码";
    
    label1.textColor = getColor(@"333333");
    
    label1.font = [UIFont systemFontOfSize:14];
    
    [self.view addSubview:label1];
    
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(19);
        make.left.equalTo(self.view).with.offset(12);
        make.height.offset(14);
        make.width.offset(100);
    }];
    
    //设置文本框
    self.textField1 = [[UITextField alloc] init];
    self.textField1.placeholder = @"******";
    //安全输入
    self.textField1.secureTextEntry = YES;
    self.textField1.textColor = getColor(@"666666");
    self.textField1.font = [UIFont systemFontOfSize:14];
    self.textField1.clearButtonMode =   UITextFieldViewModeAlways;
    [self.view addSubview:self.textField1];
    [self.textField1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label1.mas_right).with.offset(30);
        make.centerY.equalTo(label1.mas_centerY);
        make.height.offset(40);
        make.right.equalTo(self.view).with.offset(-18);
    }];

}

-(void)setUpInputPasswodAgain{

    //设置分割线
    UIView *viewOfLine2 = [[UIView alloc] initWithFrame:CGRectMake(0,  51, DEF_SCREEN_WIDTH, 1)];
    [self.view addSubview:viewOfLine2];
    viewOfLine2.backgroundColor = [UIColor colorWithRed:233/255.0f green:233/255.0f blue:233/255.0f alpha:1.0];
    
    UILabel * label2 = [[UILabel alloc] init];
    label2.text = @"请再次输入新密码";
    
    label2.textColor = getColor(@"333333");
    
    label2.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(19 + 51);
        make.left.equalTo(self.view).with.offset(12);
        make.height.offset(14);
        make.width.offset(120);
    }];
    
    self.textField2 = [[UITextField alloc] init];
    self.textField2.placeholder = @"******";
    //安全输入
    self.textField2.secureTextEntry = YES;
    self.textField2.textColor = getColor(@"666666");
    self.textField2.font = [UIFont systemFontOfSize:14];
    self.textField2.clearButtonMode =   UITextFieldViewModeAlways;
    [self.view addSubview:self.textField2];
    [self.textField2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label2.mas_right).with.offset(30);
        make.centerY.equalTo(label2.mas_centerY);
        make.height.offset(40);
        make.right.equalTo(self.view).with.offset(-18);
    }];
    

}

-(void)setUpCongigBtn{
    
    //设置分割线
    UIView *viewOfLine3 = [[UIView alloc] initWithFrame:CGRectMake(0,  51 + 51, DEF_SCREEN_WIDTH, 1)];
    [self.view addSubview:viewOfLine3];
    
    viewOfLine3.backgroundColor = [UIColor colorWithRed:233/255.0f green:233/255.0f blue:233/255.0f alpha:1.0];
    UIButton * btn = [[UIButton alloc] init];
    UIColor * color = getColor(@"FFDA44");
    [btn setBackgroundColor:color];
    [btn setTitle:@"确认" forState:UIControlStateNormal];
    UIColor * color2 = getColor(@"222222");
    [btn setTitleColor:color2 forState:UIControlStateNormal];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).with.offset(20 + 51 + 51);
        make.left.equalTo(self.view).with.offset(12);
        make.height.offset(46);
        make.right.equalTo(self.view).with.offset(-15);
    }];

}
- (void)sureClick{

    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    if ([self.textField1.text isEqualToString:self.textField2.text]) {
        [productParams setValue:token forKey:@"token"];
        [productParams setValue:self.textField2.text forKey:@"paypwd"];
        [productParams setValue:self.textField1.text forKey:@"repaypwd"];
        [[MNetworkHandler sharedInstance]conURL:adminLxlpersonSetPaypwd networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
            
            
            if ([[returnData objectForKey:@"code"]intValue]==1) {
                
                
                [PublicFunction showAlert:nil message:@"修改成功" duration:5.0f];
                
                [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
                
                
            }
            
            else {
                
                [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                
            }
            
        } failureBlock:^(NSError *error) {
            
            NSLog(@"%@",error);
            
//            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
            
        }];

        
    }else {
    
       [PublicFunction showAlert:nil message:@"请输入正确密码" duration:10.0f]; 
        
    }
    
    
    
    

}
@end
